1. /* sdfcosdv.cpp by K.Tsuru */
  2. // function ID 3207 DRADIX, reference
  3. /********************************************************************
  4. SDouble class
  5. trigonometric function cos x for |x| < pi/4 using the divide method
  6. Similar to the method using in Exp(x),x is divided into
  7. x = a(short number)+b(long but very small)
  8. and uses an addition theorem
  9. cos(x) = cos(a+b) = cos(a)*cos(b) - sin(a)*sin(b).
  10. *********************************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. SDouble CosDiv(const SDouble& x){
  15. const uint seriesFig = 4u;
  16. if(x.RdxExp() < -(int)seriesFig) return CosSeries(x); // |x| << 1.0
  17. SDouble a, b(x), y;
  18. //Make an approximation by taking out upper seriesFig figures.
  19. // x = a+b, cos(x) = cos(a+b) = cos(a)*cos(b) - sin(a)*sin(b)
  20. a = b.TakeOutFigures(seriesFig);
  21. b -= a;
  22. if( b.Sign(3207) ){
  23. //It gives a sufficient precision comparing with CosSeries().
  24. RealSize C;
  25. C.SetEffFig(x.EffFig() + 2u, C.TEMP_EXTEND);
  26. a = SinSeries(a); //a and b have same sign.
  27. b = SinSeries(b); //Both series can be rapidly evaluated.
  28. y = Sqrt((ONE - a*a)*(ONE - b*b)) - a*b;
  29. C.SetEffFig(0);
  30. } else y = CosSeries(a);
  31. return y;
  32. }

sdfcosdv.cpp : last modifiled at 2017/09/05 16:17:40(1,218 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).